﻿#region Usings
using System;
using System.ComponentModel.DataAnnotations;

using Lib.Utils.ObjUtils;
#endregion

namespace BK.Model
{
    public class CommonExpense : BaseClass<CommonExpense>, ICommonExpense, IBkEntity
    {
        #region C'tors
        public CommonExpense()
        {
        }

        public CommonExpense(ICommonExpense expense)
        {
            Assign(expense);
        }

        public CommonExpense(string author, ICommonExpense expense)
        {
            Assign(author, expense);
        }
        #endregion

        #region Instance Methods
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            if (obj.GetType() != typeof(CommonExpense))
            {
                return false;
            }
            return Equals((CommonExpense)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = (Author != null ? Author.GetHashCode() : 0);
                result = (result * 397) ^ Date.GetHashCode();
                result = (result * 397) ^ (Currency != null ? Currency.GetHashCode() : 0);
                result = (result * 397) ^ (Account != null ? Account.GetHashCode() : 0);
                result = (result * 397) ^ (Category != null ? Category.GetHashCode() : 0);
                result = (result * 397) ^ (Project != null ? Project.GetHashCode() : 0);
                result = (result * 397) ^ (Note != null ? Note.GetHashCode() : 0);
                result = (result * 397) ^ Amount.GetHashCode();
                return result;
            }
        }

        public CommonExpense Assign(ICommonExpense expense)
        {
            Date = expense.Date;
            Currency = expense.Currency;
            Account = expense.Account;
            Category = expense.Category;
            Project = expense.Project;
            Note = expense.Note;
            Amount = expense.Amount;
            return this;
        }

        public CommonExpense Assign(string author, ICommonExpense expense)
        {
            Author = author;
            return Assign(expense);
        }

        public bool Equals(CommonExpense other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            return Equals(other.Author, Author) && other.Date.Equals(Date) && 
                    Equals(other.Currency, Currency) && Equals(other.Account, Account) && 
                    Equals(other.Category, Category) && Equals(other.Project, Project) && 
                    Equals(other.Note, Note) && other.Amount == Amount || Id == other.Id;
        }
        #endregion

        #region Instance Properties
        public string Author { get; set; }
        public int Day { get { return Date.Day; } }

        public int Month { get { return Date.Month; } }
        public int Year { get { return Date.Year; } }
        #endregion

        #region IBkEntity Members
        [Key]
        public int Id { get; set; }
        #endregion

        #region ICommonExpense Members
        public DateTime Date { get; set; }
        public string Currency { get; set; }
        public string Account { get; set; }
        public string Category { get; set; }
        public string Project { get; set; }
        public string Note { get; set; }
        public decimal Amount { get; set; }
        #endregion
    }
}